home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6430 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: in2.uu.net!van-bc!uniserve!usenet
  2. From: nowher@anyplace.com (Chris)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help! I am baffled! (newbie) - problem.txt [1/1]
  5. Date: 8 Feb 1996 06:09:50 GMT
  6. Organization: UNIServe Online
  7. Distribution: world
  8. Message-ID: <4fc43e$cj8@atlas.uniserve.com>
  9. References: <4euosb$qnj@atlas.uniserve.com> <4f8kvg$ffl@sam.inforamp.net>
  10. NNTP-Posting-Host: van0217.tvs.net
  11. Mime-Version: 1.0
  12. X-Newsreader: WinVN 0.99.2
  13.  
  14. In article <4f8kvg$ffl@sam.inforamp.net>, rmorin@inforamp.net says...
  15. >
  16. >In article <4euosb$qnj@atlas.uniserve.com>, nowher@anyplace.com (Chris) 
  17. wrote:
  18. >>
  19. >>TempPart.PartNum = new char[15];
  20. >>...
  21. >>TempPart.PartNum=TempStr;     
  22. >>
  23. >
  24. >Here's your problem.  You allocate a string in the first statement.  
  25. Thus you 
  26. >have a string that is pointed to by TempPart.PartNum.  Then you set 
  27. >TempPart.PartNum to TempStr.  This does not copy the string, this only 
  28. changes 
  29. >the pointer.  Now that first string you pointed to is lost in space and 
  30. you 
  31. >are running into big pointer problems when TempStr get deallocated.  To 
  32. copy a 
  33. >string use strcpy or a variant of it.  I might be wrong, since you 
  34. included 
  35. >only a portion of the code.
  36. >
  37. >Agrivar
  38.  
  39.  
  40.   Thanks for the tip! I tried it again with 
  41. strcpy(TempPart.PartNum,TempStr) and it worked fine.
  42. I figured it was a problem with the way I was using the pointers, but I 
  43. was looking at it from a different angle.
  44.  
  45. Thanks again,
  46. Chris.
  47.  
  48.